using BuildingBlocks.Presentation.Endpoints;
using BuildingBlocks.Presentation.Results;
using Mediator;

namespace Catalog.Api.Features.CatalogItems.GetItems;

internal sealed class GetCatalogItemsEndpoint : IEndpoint
{
    public void MapEndpoint(IEndpointRouteBuilder app)
    {
        app.MapGet(Routes.Base, async (IMediator mediator, CancellationToken cancellationToken) =>
            {
                var result = await mediator.Send(new GetCatalogItemsQuery(), cancellationToken);
                return result.Match(Results.Ok, ApiResponse.Problem);
            })
            .WithName("GetCatalogItems")
            .WithTags("Catalog");
    }
}
